package com.yt.ds.chapter2;

import com.yt.ds.util.SortUtil;

/**
 * @Author: lzf
 * @Date: 2020/7/15 14:37
 * @Description: 冒泡排序 [补充用，书上没提]
 */
public class BubbleSort implements Sort {
    @Override
    public Comparable[] sort(Comparable[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                if (SortUtil.less(array, j + 1, j)) {
                    SortUtil.exch(array, j + 1, j);
                }
            }
        }
        return array;
    }
}
